package com.xzc.seckill.controller;

import com.xzc.seckill.pojo.User;
import com.xzc.seckill.service.UserService;
import com.xzc.seckill.vo.RespBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author 徐生
 * @version 1.0
 * Date 2024/4/7 14:31
 * Description: UserController
 */
@Controller
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserService userService;

    /**
     * 返回用户信息, 同时我们也演示如何携带参数
     */
    @RequestMapping("/info")
    @ResponseBody
    public RespBean info(User user, String address) {
        //System.out.println("address->" + address);
        return RespBean.success(user);
    }

    //处理更新密码
    @RequestMapping("/updatePwd/{userTicket}/{password}")
    @ResponseBody
    public RespBean updatePassword(@PathVariable String userTicket, @PathVariable String password, HttpServletRequest request, HttpServletResponse response){
        //通过地址栏进行测试 ——> http://localhost:8080/user/updatePwd?userTicket=007fba5aebf0430d8747992c37863bf7&password=1234
        //通过路径参数测试  ——> http://localhost:8080/user/updatePwd/007fba5aebf0430d8747992c37863bf7/1234
        return userService.updatePassword(userTicket,password,request,response);
    }
}